﻿using Ice.Extension;
using System.Collections.Generic;
using System.Linq;

namespace FoftmAging.Core
{
    /// <summary>
    /// 功能描述    ：Config  
    /// 创 建 者    ：石斌
    /// 创建日期    ：2025/10/9 21:17:51 
    /// </summary>
    public class Config
    {
        public int GroupCount { get; set; } = 2;
        public int BaudRate { get; set; } = 9600;

        /// <summary>
        /// 间隔毫秒
        /// </summary>
        public int IntervalMillisecond { get; set; } = 1;

        public double MinTemperature { get; set; } = -10;
        public double MaxTemperature { get; set; } = 30;
        public string GroupSettings { get; set; }

        /// <summary>
        /// 老化后重置通道
        /// </summary>
        public bool IsResetChannel { get; set; }


        /// <summary>
        /// 模块启动数据(秒)
        /// </summary>
        public int StartupTime { get; set; } = 60;


        public List<GroupSetting> GetGroupSettings()
        {
            var list = new List<GroupSetting>();
            if (string.IsNullOrEmpty(this.GroupSettings))
            {
                for (int i = 0; i < 8; i++)
                {
                    list.Add(new GroupSetting
                    {
                        GroupNo = i + 1,
                        PortName = "",
                        ChannelCount = 10
                    });
                }

                return list;
            }
            var arr = GroupSettings.Split('|');
            foreach (var item in arr)
            {
                var arr1 = item.Split(',');
                list.Add(new GroupSetting
                {
                    GroupNo = arr1[0].ToInt32(),
                    PortName = arr1[1],
                    ChannelCount = arr1[2].ToInt32(),
                });
            }
            return list;
        }

        public void SetGroupSettings(List<GroupSetting> settings)
        {
            this.GroupSettings = string.Join("|", settings.Select(s => $"{s.GroupNo},{s.PortName},{s.ChannelCount}"));
        }
    }
}